package com.rwb.reconciliation.base;

import com.rwb.reconciliation.dto.BatchFile;
import com.rwb.reconciliation.mapper.BatchDetailMapper;
import com.rwb.reconciliation.mapper.BatchFileMapper;
import com.rwb.reconciliation.vo.ReconciliationParamVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 对账基类
 *
 * @Auther: ruwenbo
 * @Date: 2018/9/23 13:00
 * @Description:
 */
public abstract class AbstractReconciliation {

    private static final Logger logger = LoggerFactory.getLogger(AbstractReconciliation.class);


    @Autowired
    private BatchFileMapper batchFileMapper;

    @Autowired
    private BatchDetailMapper batchDetailMapper;

    /**
     * 校验文件是否处理过
     * @param paramVO
     */
    protected boolean checkBatchFile(ReconciliationParamVO paramVO) {

        logger.info("########### 验证对账是否已处理 start ###########");

        BatchFile batchFile = batchFileMapper.queryBatchFileByNameAndType(paramVO.getFileName(), paramVO.getFileType());

        if (batchFile == null) {
            logger.info("########### 验证通过(不存在对账批次), 继续后续对账处理 ###########");
            return false;
        }

        if ("00".equals(batchFile.getHandleStatus()) || "04".equals(batchFile.getHandleStatus())) {
            logger.info("########### 验证通过(已存在对账批次, 处理状态为:{}), 继续后续对账处理 ###########", batchFile.getHandleStatus());
            return false;
        }
        return true;
    }

    /**
     * 对入参参数校验
     *
     * @param paramVO
     * @return
     */
    protected boolean checkParamVO(ReconciliationParamVO paramVO) {

        return paramVO == null || StringUtils.isEmpty(paramVO.getFileName())
                || StringUtils.isEmpty(paramVO.getFileType())
                || StringUtils.isEmpty(paramVO.getTxnDate());
    }
}
